Socket
Socket
Sign inDemoInstall

end-of-stream

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

end-of-stream

Call a callback when a readable/writable/duplex stream has completed or failed.


Version published
Weekly downloads
34M
increased by5.67%
Maintainers
1
Weekly downloads
 
Created

What is end-of-stream?

The end-of-stream npm package is designed to help developers handle the end or error conditions of a stream more easily. It provides a simple way to execute a callback when a stream has finished or failed, making it easier to manage streams in Node.js applications.

What are end-of-stream's main functionalities?

Callback on stream end

This feature allows you to execute a callback function when the stream ends or encounters an error. The code sample demonstrates how to use end-of-stream with a file read stream.

const eos = require('end-of-stream');
const fs = require('fs');

const readStream = fs.createReadStream('file.txt');
eos(readStream, function(err) {
  if (err) return console.log('Stream had an error or closed early');
  console.log('Stream has ended');
});

Promise support

This feature demonstrates how to use end-of-stream with promises, providing a more modern approach to handling stream completion. It uses the `promisify` utility from Node.js to convert the eos callback pattern into a promise.

const eos = require('end-of-stream');
const fs = require('fs');
const { promisify } = require('util');

const eosPromise = promisify(eos);

const readStream = fs.createReadStream('file.txt');
eosPromise(readStream).then(() => console.log('Stream has ended')).catch(err => console.log('Stream had an error or closed early'));

Other packages similar to end-of-stream

Keywords

FAQs

Package last updated on 25 Sep 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc